package design.factorys

/**
 *工厂模式
 *@description:
 *@author: liushilin
 *@time: 2019/10/28 4:44 下午
 *
 */

interface Product {
    fun showName()
}

class ProductA(private val strType: String) : Product {
    override fun showName() {
        println("当前构建对象是：$strType")
    }
}
class ProductB(private val strType: String) : Product by ProductA(strType)

/**
 * 创建工厂
 */
class FruitsFactory {

    fun createType(type: String): Product? {
        return when (type) {
            "A" -> {
                ProductA(type)
            }
            "B" -> {
                ProductB(type)
            }
            else -> null
        }
    }

}

fun main() {
    val productA = FruitsFactory().createType("LeAmon")
    productA?.showName()
    val productB = FruitsFactory().createType("B")
    productB?.showName()
}
